﻿<%@ Page Title="Title" Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>"
    MasterPageFile="~/Views/Shared/Site.Master" %>

<%@ Register TagPrefix="o" Namespace="Omu.AwesomeWebForms" Assembly="Omu.AwesomeWebForms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e8b65a0968999f7e" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">
</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
    <h3>
        Lookup</h3>
    <form runat="server">
    <o:Lookup runat="server" ID="loko" GetUrl="~/svc/aja.svc/FruitGet" SearchUrl='~/svc/aja.svc/FruitSearch'
        Value="1" />
    </form>
    <p class="te">
        The Lookup requires 2 urls to service methods:
    </p>
    <ul class="lst te">
        <li><b>GetUrl</b> - used to show the value in the readonly field, it will receive a
            <b>v</b> parameter which is going to be the <b>key</b> of the selected item</li>
        <li><b>SearchUrl</b> - used for searching, this method will receive a search parameter
            (the value that the user has entered in the search textbox), and must return a <b>LookupResult</b>
            object.
            <br />
            <br />
            The <b>LookupResult</b> has 2 properties:
            <ul class="lst">
                <li>Items - a collection of KeyContent objects and it is the search result that the
                    user will see</li>
                <li>More - a bool property used for pagination, if you set it to true the "more" button
                    will appear, and when the "more" button is going to be clicked the SearchUrl will
                    be called but with an additional page parameter , on the first click on "more" button
                    the page will be = to 2, on the second click it will be = 3, and so on, but when
                    the search button is clicked the page will reset to 1 (the page parameter is always
                    sent with value = 1, but if you don't use pagination you can just ignore it )</li>
            </ul>
        </li>
    </ul>
    <p class="te">
        here's a basic example:
    </p>
    <pre class="prettyprint">
&lt;o:Lookup runat=&quot;server&quot; ID=&quot;Fruit&quot; GetUrl=&quot;~/svc/aja.svc/FruitGet&quot; SearchUrl='~/svc/aja.svc/FruitSearch'  Value=&quot;1&quot; /&gt;
</pre>
    <p class="te">
        and the service methods:
    </p>
    <pre class="prettyprint">
[WebGet]
[OperationContract]
public string FruitGet(string v)
{
    return Fruits.Where(o => o.Id.ToString() == v).Single().Name;
}

[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search)
{
    var items = Fruits.Where(o =&gt; o.Name.Contains(search))
        .Select(f =&gt; new KeyContent { Key = f.Id, Content = f.Name });
            
    return new LookupResult
    {
        Items = items
    };
}
</pre>
    <br />
    <h3>
        Using pagination</h3>
    <p class="te">
        As mentioned above to use pagination you need to return a value for the "More" property
        (more = is there more results) in the LookupResult, so here's an example:
    </p>
    <pre class="prettyprint">
[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search, int page)
{   
    var sel = selected.GetIntArray();

    var items = Fruits.Where(o =&gt; o.Name.Contains(search))
        .Select(f =&gt; new KeyContent { Key = f.Id, Content = f.Name });

    const int pageSize = 5;
    return new LookupResult
    {
        Items = items.Skip((page - 1) * pageSize).Take(pageSize),
        More = items.Count() &gt; page * pageSize
    };
}
</pre>
    <h3>
        Binding to parents, parameters</h3>
    <p class="te">
        The Lookup can be bound to one or multiple parents, and parameters with values can
        be sent, all exactly like the <a href="<%=Url.Action("AjaxDropdown") %>">AjaxDropdown</a>,
        additional parameters (parents, predefined values) will be sent to SearchUrl and GetUrl.
    </p>
    <h3>
        Misc properties</h3>
    <table class="ap te">
        <tr>
            <td>
                ClearButton
            </td>
            <td>
                if true will add a "x" button used to clear the value of Lookup
            </td>
        </tr>
        <tr>
            <td>
                Width
            </td>
            <td>
                the width in px of the lookup window
            </td>
        </tr>
        <tr>
            <td>
                Height
            </td>
            <td>
                the height in px of the lookup window
            </td>
        </tr>
        <tr>
            <td>
                FullScreen
            </td>
            <td>
                if true Width and Height are ignored and the lookup window will take all the available
                width and height
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        $(function () {
            prettyPrint();
        });
    </script>
</asp:Content>
